import { defineStore } from 'pinia'
import { saveToLocalStore, loadLocalStore, removeToLocalStore } from '@/common/index'
interface ConfigType {
  [key: string]: any // 使用索引签名来允许任意字符串键和任意值
}
export const configStore = defineStore('config', {
  state: () => {
    return {
      config: <ConfigType>{},
    }
  },
  // 也可以这样定义
  // state: () => ({ count: 0 })
  actions: {
    // 清空config
    clearConfig() {
      this.config = {}
      removeToLocalStore('config')
    },
    // 设置config
    setConfig(key: any, value: any) {
      // this.config.key = value;给config添加属性
      this.config[key] = value
      // console.log('saveConfig',this.config);

      saveToLocalStore('config', this.config)
    },
  },
  // persist: true, //持久化
  persist: {
    storage: localStorage,
    pick: ['config'],
  },
})
